#if NETFRAMEWORK

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit.Internal;

public class FSharpAcceptanceTestV3Assembly(string? basePath = null) :
	FSharpAcceptanceTestAssembly(basePath)
{
	protected override string AssemblyFileExtension => ".exe";

	protected override IEnumerable<string> GetAdditionalCode()
	{
		foreach (var value in base.GetAdditionalCode())
			yield return value;

		var testFolder = Path.GetDirectoryName(typeof(FSharpAcceptanceTestV3Assembly).Assembly.GetLocalCodeBase());
		Guard.NotNull(() => $"Path.GetDirectoryName(\"{typeof(FSharpAcceptanceTestV3Assembly).Assembly.GetLocalCodeBase()}\") returned null", testFolder);

		// Use the real entrypoint that we ship to end users
		var programPath = Path.Combine(testFolder, "..", "..", "..", "..", "xunit.v3.core", "Package", "content", "AutoGeneratedEntryPoint.fs");
		programPath = Path.GetFullPath(programPath);
		Guard.ArgumentValid(() => $"Cannot find '{programPath}' to include into compilation", File.Exists(programPath));
		yield return File.ReadAllText(programPath);
	}

	protected override IEnumerable<string> GetStandardReferences() =>
		base
			.GetStandardReferences()
			.Concat([
				"mscorlib.dll",
				"System.Threading.Tasks.Extensions.dll",
				"xunit.v3.assert.dll",
				"xunit.v3.common.dll",
				"xunit.v3.core.dll",
				"xunit.v3.runner.common.dll",
				"xunit.v3.runner.inproc.console.dll",
			]);

	public static async Task<FSharpAcceptanceTestV3Assembly> CreateIn(
		string basePath,
		string code,
		params string[] references)
	{
		Guard.ArgumentNotNull(basePath);
		Guard.ArgumentNotNull(code);
		Guard.ArgumentNotNull(references);

		basePath = Path.GetFullPath(basePath);
		Guard.ArgumentValid(() => $"Base path '{basePath}' does not exist", Directory.Exists(basePath), nameof(basePath));

		var assembly = new FSharpAcceptanceTestV3Assembly();
		await assembly.Compile([code], references);
		return assembly;
	}
}

#endif
